<template>
  <div class="price-setting pd-20">
    <el-radio-group v-model="ecgType"
                    @change="changeRadio">
      <el-radio-button v-for="item in listData"
                       :label="item.value"
                       :key="item.value">{{item.label}}
      </el-radio-button>
    </el-radio-group>
    <div class="mt-20">
      <el-table border
                :data="tableData"
                v-if="currentIndex === 3">
        <el-table-column label="测试时长"
                         prop="testDuration">
          <template slot-scope="scope">
            <span v-if="scope.row.testDuration === 1">24小时</span>
            <span v-if="scope.row.testDuration === 2">48小时</span>
            <span v-if="scope.row.testDuration === 3">72小时</span>
          </template>
        </el-table-column>
        <el-table-column label="解读服务费用（元）"
                         prop="readPrice">
          <template slot-scope="scope">
            <el-input v-model="scope.row.price"
                      placeholder="请输入解读服务费用"
                      class="w-200"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <el-table border
                :data="tableList"
                v-show="currentIndex === 4">
        <el-table-column label="数据最少上传条数"
                         prop="dataCountLow">
          <template slot-scope="scope">
            <el-input v-model="scope.row.dataCountLow"
                      placeholder="请输入数据最少上传条数"
                      class="w-200"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="解读服务费用（元）"
                         prop="price">
          <template slot-scope="scope">
            <el-input v-model="scope.row.price"
                      placeholder="请输入解读服务费用"
                      class="w-200"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary"
                       @click="configBtn(scope.row)">医生配置</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="save-btn mt-20">
        <el-button type="primary"
                   @click="submitBtn(currentIndex, saveType)">保 存</el-button>
      </div>
      <doctors-config :doctorsInfo="doctorsObj"
                      :visible.sync="isShowDoctorsConfig"
                      :getParentList="getList"
                      v-if="isShowDoctorsConfig"></doctors-config>
    </div>
  </div>
</template>
<script>
import doctorsConfig from './doctorsConfig'
export default {
  data () {
    return {
      isShowDoctorsConfig: false,
      ecgType: 3,
      listData: [
        { label: '动态心电费用设置', value: 3 },
        { label: '30s心电费用设置', value: 4 }
      ],
      currentIndex: 3,
      tableData: [], // 动态心电费用设置
      tableList: [], // 30s心电费用设置
      doctorsObj: {},
      saveType: '',
      ecgPriceDtos: {}
    }
  },
  methods: {
    // 选择
    changeRadio (val) {
      this.currentIndex = val
      this.getList()
    },
    // 获取数据
    async getList () {
      const { data: res } = await this.post(this.api.ECG.getDoctorsConfigDetail, {
        ecgType: this.currentIndex
      })

      if (res.code === '200') {
        if (res.object.length === 0) {
          this.tableData = [
            { ecgType: 3, testDuration: 1, dataCountLow: null, price: null },
            { ecgType: 3, testDuration: 2, dataCountLow: null, price: null },
            { ecgType: 3, testDuration: 3, dataCountLow: null, price: null },
          ]
          this.tableList = [
            { ecgType: 4, testDuration: null, dataCountLow: null, price: null },
          ]
        } else {
          this.tableData = res.object
          this.tableList = res.object
        }

      } else {
        this.$message.error(res.message)
      }
    },
    // 保存数据
    async submitBtn (currentIndex, data) {
      if (currentIndex === 3) {
        data = this.tableData
      }
      if (currentIndex === 4) {
        data = this.tableList
      }
      const { data: res } = await this.post(this.api.ECG.setECGDCost, { ecgPriceDtos: data })
      if (res.code === '200') {
        this.$message.success('保存成功')
      } else {
        this.$message.error(res.message)
      }
    },
    configBtn (row) {
      this.isShowDoctorsConfig = !this.isShowDoctorsConfig
      this.doctorsObj = row
    },
  },
  created () {
    this.getList()
  },
  components: {
    'doctors-config': doctorsConfig
  }
}
</script>
<style scoped>
.save-btn {
  text-align: center;
}
</style>